package com.tianqu.tms.www.user.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.user.controller.UserRoleUpdateInputController;
import com.tianqu.tms.www.user.viewhelper.UserDetailViewHelper;

/**
 * @author zhangxueliang
 * 用户角色修改录入
 */
public class UserRoleUpdateInputAction extends TmsAction{
	private Logger logger = Logger.getLogger(UserRoleUpdateInputAction.class);
	private static final String ID = "id";
	@SuppressWarnings("unchecked")
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		UserRoleUpdateInputController controller = new UserRoleUpdateInputController();
		String id = "";
		
		if(request.getParameter(ID) != null ){
			id = request.getParameter(ID);
		}else{
			id = (String)uc.getAttribute(ID);
		}
		
		uc.setAttribute(ID, id);
		controller.execute(uc);
		
		List roleList = (List)uc.getAttribute(UserRoleUpdateInputController.ROLELIST);
		UserDetailViewHelper viewhelper = new UserDetailViewHelper();
		viewhelper.setRoleList(roleList);
		uc.setAttribute(TmsConstants.VIEWHELP, viewhelper);
		request.setAttribute("viewhelp", viewhelper);
		
		logger.debug(this.getClass().getName() + "#doAction was completed.");				
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
